﻿@{
    ViewBag.Title = "巡检单查询";
    Layout = "~/Views/Shared/_LayoutKoJS.cshtml";
}

@*<script src="../../../../Scripts/FusionChart/js/FusionCharts.js" type="text/javascript"></script>*@
@*<script src="~/Scripts/jquery-ui-timepicker-addon.js" type="text/javascript"></script>*@
<div class="aux-body">
    <!--<h1 class="itemtitle">My Resource</h1> -->
    <div class="aux-tabcontent">
        <div class="fx-grid">
            <div id="fx-scrollbar" style="width: 900px;">
                <!-- style变化 height:650px; -->
                <div id="fx-scrollbar-scrollable" style="width: 950px;">
                    <!-- style变化 -->
                    <div class="fx-grid-container fx-scrollbar-content" style="overflow: visible; width: 900px;">
                        <!-- style变化 -->
                        <div class="quickStarttab" style="height: 170px">
                            <form id="KSForm">
                                <div id="Ticketfield">
                                    <div class="quickStarttab-item">
                                        <label>租户名称：</label>
                                        <select id="TenantsName" style="width: 272px">
                                            <option value=""></option>
                                            @{foreach (var i in ViewBag.OfficeSelection)
                                              { 
                                                <option value=@i>@i</option>
                                              }
                                            }
                                        </select>
                                        @* <input type="text" name="" id="TenantsName" >*@
                                    </div>
                                    <div class="quickStarttab-item">
                                        <label>模板名称：</label>
                                        <input type="text" name="" id="cChr_Name">
                                    </div>
                                    <div class="quickStarttab-item">
                                        <label>巡检单名称：</label>
                                        <input type="text" name="" id="TcChr_Name">
                                    </div>
                                    <div class="quickStarttab-item">
                                        <label>巡检执行人：</label>
                                        <input type="text" name="" id="TcChr_FullName">
                                    </div>
                                    <div class="quickStarttab-item">
                                        @*id="cChr_Descriptions"*@
                                        <label>模板创建时间：</label>
                                        <input type="text" id="TemplateStartDate" name="">
                                    </div>
                                    <div class="quickStarttab-item">
                                        @*id="cChr_Descriptions"*@
                                        <label>至：</label>
                                        <input type="text" id="TemplateEndDate" name="">
                                    </div>
                                    <div class="quickStarttab-item">
                                        <label>巡检单生成时间：</label>
                                        <input type="text" name="" id="PlanStartDate">
                                    </div>
                                    <div class="quickStarttab-item">
                                        <label>至：</label>
                                        <input type="text" name="" id="PlanEndDate">
                                    </div>
                                    <div class="quickStarttab-item">
                                        <label>正常或异常：</label>
                                        <select id="YesOrNo" style="width: 272px">
                                            <option value=""></option>
                                            <option value="正常">正常</option>
                                            <option value="异常">异常</option>
                                        </select>
                                        @* <input type="text" name="" id="TenantsName" >*@
                                    </div>
                                    <div class="quickStarttab-item" style="width: 100%;">
                                        <div style="float: right; display: inline-block; margin-right: 42px;margin-top: -30px;">
                                            @*<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="FormSearch" ><span class="ui-button-text" onclick="TaskFormSearch()">Search</span></button>*@
                                            <input type="button" name="" value="清空" style="width: 70px; height: 35px;" onclick="TaskFormClear()" />
                                            <input type="button" name="" value="查询" style="width: 70px; height: 35px;" onclick="TaskFormSearch()" />
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div>
                            <table id="gridTableList">
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>


@section scripts {
    <link href="~/Scripts/jquery-ui-timepicker-addon.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-ui-timepicker-addon.js"></script>
    @*<script src="http://my97date/My97DatePicker4.7.2/WdatePicker.js"></script>*@
    <script type="text/javascript">
        $("#LayoutSearch").addClass("selected");
        $(document).ready(function () {
            //$("#start").datepicker();
            $("#TemplateStartDate").datetimepicker({
                showUpDown: true,
                showSecond: true,
                //showMillisec: true,
                //timeFormat: 'hh:mm:ss:l'
                timeFormat: "hh:mm:ss",
                dateFormat: "yy-mm-dd",
                changeYear: true,
            });
            $("#TemplateEndDate").datetimepicker({
                showSecond: true,
                timeFormat: "hh:mm:ss",
                dateFormat: "yy-mm-dd",
                changeYear: true
            });
            $("#PlanStartDate").datetimepicker({
                showSecond: true,
                timeFormat: "hh:mm:ss",
                dateFormat: "yy-mm-dd",
                changeYear: true
            });
            $("#PlanEndDate").datetimepicker({
                showSecond: true,
                timeFormat: "hh:mm:ss",
                dateFormat: "yy-mm-dd",
                changeYear: true
            });
            //$('#TemplateStartDate').datepicker({ dateFormat: 'yy-mm-dd', changeYear: true, buttonText: 'Choose' });
            //$("#TemplateEndDate").datepicker({ dateFormat: 'yy-mm-dd', changeYear: true, buttonText: 'Choose' });
            //$('#PlanStartDate').datepicker({ dateFormat: 'yy-mm-dd', changeYear: true, buttonText: 'Choose' });
            //$("#PlanEndDate").datepicker({ dateFormat: 'yy-mm-dd', changeYear: true, buttonText: 'Choose' });
            $("#gridTableList").jqGrid({
            @*url: '/API'+'@Url.Action("GetRule", "InspectionRuleAPI")',
            datatype: 'json',*@
                url: '',
                datatype: 'local',
                rowNum: 10000,
                colNames: ['巡检单ID', '巡检单名称', '巡检单描述', '状态', '执行人', 'RequestID', 'Submitter', '巡检单生成时间', 'AssignedTo', 'LastModifiedBy', '最后更新时间', 'ShortDescription', 'StatusHistory', 'TcChr_Department'
                    , 'TcChr_Office', 'TcChr_MarkAsDelete', 'TcChr_TicketID', 'OcChr_MarkAsDelete'],
                colModel: [
                    { index: "636871917", name: "TaskID", sorttype: "text", align: "center", width: 100 },
                    { index: "636871911", name: "TcChr_Name", sorttype: "text" },
                    { index: "636871913", name: "TcChr_Description", sorttype: "text" },
                    { index: "636870918", name: "Status", sorttype: "text", formatter: FormateStatus, width: 60 },
                    { index: "636871912", name: "TcChr_FullName", sorttype: "text", width: 80 },
                    { index: "1", name: "RequestID", key: true, sorttype: "text", hidden: true },
                    { index: "636870913", name: "Submitter", sorttype: "text", hidden: true },
                    //{ index: "636870914", name: "cDat_TicketTime", sorttype: "date", formatter: IScDat_TicketTime, width: 120 },
                    { index: "636870914", name: "CreateDate", sorttype: "date", formatter: ISCreateDate, width: 120 },
                    { index: "636870915", name: "AssignedTo", sorttype: "text", hidden: true },
                    { index: "636870916", name: "LastModifiedBy", sorttype: "text", hidden: true },
                    { index: "636870917", name: "ModifiedDate", sorttype: "date", formatter: DateModify, width: 120 },
                    { index: "636870919", name: "ShortDescription", sorttype: "text", hidden: true },
                    { index: "636870910", name: "StatusHistory", sorttype: "text", hidden: true },
                    { index: "636870911", name: "TcChr_Department", sorttype: "text", hidden: true },
                    { index: "636870912", name: "TcChr_Office", sorttype: "text", hidden: true },
                    { index: "636871914", name: "TcChr_MarkAsDelete", sorttype: "text", hidden: true },
                    { index: "636871915", name: "TcChr_TicketID", sorttype: "text", hidden: true },
                    { index: "636871916", name: "OcChr_MarkAsDelete", sorttype: "text", hidden: true },
                ],
                jsonReader: {
                    repeatitems: false,
                    id: "RequestID"
                },
                mtype: "GET",
                autowidth: true,
                sortname: 'ModifiedDate',
                sortorder: 'desc',
                postData: {
                    Permission: 'public',
                }, //发送数据
                prmNames: {
                    id: 'Type'
                },
                scrollOffset: 0,
                height: "280",
                width: "980",
                viewrecords: true,
                gridview: true,

                onSelectRow: function () {
                },
                ondblClickRow: function () {
                    var IsSearch = "Search"
                    var id = jQuery("#gridTableList").jqGrid('getGridParam', 'selrow');
                    if (id) {
                        var ret = jQuery("#gridTableList").jqGrid('getRowData', id);
                        //alert("id=" + ret.RequestID + " invdate=" + ret.ShortDescription + "...");
                        window.location.href = "/InspectionTask/Index?GTicketID=" + ret.TaskID + "&PageName=" + IsSearch;
                        //window.open("../InspectionTicket/Index?GTicketID=" + ret.TaskID);
                    } else {
                        alert("Please select row");
                    }
                },
                gridComplete: function () {
                },
                loadComplete: function () {
                }
            });
            //LoadHosts();
            TaskFormSearch();
        });
@*        function LoadHosts() {
            var IsTaskID = '@ViewBag.FullName';
            //alert(IsTaskID);
            var data = {};
            jQuery("#gridTableList").jqGrid("setGridParam", {
                //url: "/API/InspectionTicketAPI/GetAll", //设置表格的url
                url: "/API/InspectionTaskAPI/GetTaskList/", //设置表格的url
                datatype: "json", //设置数据类型
                postData: { strJson: data }
            }).trigger("reloadGrid");
        }*@

        function FormateStatus(cellvalue, options, rowObject) {
            var Status = rowObject.Status;
            switch (Status) {
                //case 0: return '新建';
                case 1: return '进行中';
                case 2: return ' 已取消';
                case 3: return '已完成';
            }
        }

        function DateModify(cellvalue, options, rowObject) {
            return rowObject.ModifiedDate.replace("T", " ").replace("+08:00", "");
        }

        function ISCreateDate(cellvalue, options, rowObject) {
            return rowObject.CreateDate.replace("T", " ").replace("+08:00", "");
        }
        function IScDat_TicketTime(cellvalue, options, rowObject) {
            return rowObject.cDat_TicketTime.replace("T", " ").replace("+08:00", "");
        }
        function TaskFormClear() {
            $('#TenantsName').val("");
            $('#YesOrNo').val("");
            var txtClear = document.getElementsByTagName("input");
            for (var i = 0; i < txtClear.length; i++) {
                if (txtClear[i].type == "text" || txtClear[i].type == "checkbox") {
                    txtClear[i].value = "";
                }
            }
        }

        function TaskFormSearch() {
            var IsTenantsName = $('#TenantsName').val();
            var IscChr_Name = $('#cChr_Name').val();
            var IsTcChr_Name = $('#TcChr_Name').val();
            var IsTcChr_FullName = $('#TcChr_FullName').val();
            var IsTemplateStartDate = $('#TemplateStartDate').val();
            var IsTemplateEndDate = $('#TemplateEndDate').val();
            var IsPlanStartDate = $('#PlanStartDate').val();
            var IsPlanEndDate = $('#PlanEndDate').val();
            var IsYesOrNo = $('#YesOrNo').val();
            var data = {};
            jQuery("#gridTableList").jqGrid("setGridParam", {
                //url: "/API/InspectionTicketAPI/GetAll", //设置表格的url
                url: "/API/InspectionTaskAPI/GetSearchList?TenantsName=" + IsTenantsName + "&cChr_Name=" + IscChr_Name + "&TcChr_Name=" + IsTcChr_Name + "&TcChr_FullName=" + IsTcChr_FullName + "&cDat_TicketTime=" + IsTemplateStartDate + "&cDat_TicketEndTime=" + IsTemplateEndDate + "&CreateDate=" + IsPlanStartDate + "&CreateEndDate=" + IsPlanEndDate + "&cChr_Status=" + IsYesOrNo, //设置表格的url
                datatype: "json", //设置数据类型
                postData: { strJson: data }
            }).trigger("reloadGrid");
        }
    </script>
}
